/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.nuage.tiow.ui;

import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import java.util.List;
import org.nuage.tiow.ui.warhost.WarhostEditor;
import org.nuage.tiow.vo.user.Player;

/**
 *
 * @author quentina
 */
public class PlayersPanel extends Panel {

    public PlayersPanel(List<Player> players) {
        setCaption("Campaign players");
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        addComponent(horizontalLayout);

        Table table = new Table("", new BeanItemContainer(players));
        table.setSelectable(true);
        table.setImmediate(true);
        table.setVisibleColumns(new Object[]{"name"});
        horizontalLayout.addComponent(table);

        final VerticalLayout verticalLayout = new VerticalLayout();
        horizontalLayout.addComponent(verticalLayout);

        table.addListener(new ValueChangeListener() {

            public void valueChange(ValueChangeEvent event) {
                final Object item = event.getProperty().getValue();
                if (item != null) {
                    Player player = (Player) item;
                    WarhostEditor warhostList = new WarhostEditor(player.getWarhost());
                    verticalLayout.removeAllComponents();
                    verticalLayout.addComponent(warhostList);
                }
            }
        });
    }
}
